<!--
 * @Description: 
 * @Author: charles
 * @Date: 2021-07-12 10:56:47
 * @LastEditors: charles
 * @LastEditTime: 2021-08-01 14:08:29
-->
<template>
  <div>
    <!-- 研学项目开始 -->
    <div class="projects">
      <div class="wrapper">
        <!-- <div class="title">研学精选项目</div> -->
        <div class="project" v-for="item in articles" :key="item.id" @click="toArticleDetail(item.id)">
          <div class="left" >
            <img
              style="width: 100%"
              :src=item.cover
              alt=""
            />
          </div>
          <div class="right">
            <div class="name">
              {{item.title}}
            </div>
            <div class="time">{{item.publishTime|fmtDate}}</div>
            <div class="content">
              阅读次数：{{item.readTimes}} 点赞次数：{{item.thumpUp}}
            </div>
          </div>
        </div>
      </div>
    </div>
    <!-- 研学项目结束 -->
  </div>
</template>

<script>
import {get} from '../utils/request'
export default {
  data(){
    return{
      // 向后台传递的参数
      list:{
        page:1,
        pageSize:10,
        categoryId:this.$route.query.categoryId
      },
      articles:''
    }
  },
  // 侦听器
  watch:{
    '$route.query.categoryId':function(){
      this.list.categoryId = this.$route.query.categoryId
      // 刷新页面
      this.findArticleById()
    }
    
  },
  methods:{
    // 通过categoryId查询资讯信息
    findArticleById(){
      // 数据交互
      get('/index/article/pageQuery',this.list).then(res=>{
        this.articles = res.data.list
        // console.log(res);
      })
    },
    toArticleDetail(id){
      this.$router.push({
        path:'/article',
        query:{
          id
        }
      })
    }
  },
  created(){
    this.findArticleById()
  }
}
</script>

<style lang="scss" scoped>
.projects {
  .wrapper {
    padding: 2em 0;
    // height: 500px;
    width: 1240px;
    // background-color: teal;
    .title {
      font-size: 20px;
      line-height: 4em;
      border-bottom: 1px solid #f4f4f4;
    }
    .project {
      display: flex;
      padding: 1em 0;
      border-bottom: 1px solid #f4f4f4;
      cursor: pointer;
      .left {
        width: 300px;
        height: 200px;
        background-color: #f4f4f4;
        border-radius: 5px;
        overflow: hidden;
      }
      .right {
        flex: 1;
        // background-color: seagreen;
        padding: 0 2em;
        .name {
          font-size: 15px;
          font-weight: 700;
        }
        .time {
          margin: 1em 0;
        }
        .content {
          line-height: 2em;
        }
      }
    }
  }
}
</style>